package com.woniuxy.service.impl;

import com.woniuxy.entity.Address;
import com.woniuxy.entity.Community;
import com.woniuxy.entity.Picture;
import com.woniuxy.mapper.CommunityMapper;
import com.woniuxy.service.CommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class CommunityServiceImpl implements CommunityService {
    @Autowired
    private CommunityMapper communityMapper;
    @Override
    public List<Community> communityList() {
        return communityMapper.selectCommunityList();
    }

    @Override
    public Integer count() {
        return communityMapper.selectCount();
    }

    @Override
    public Integer roomCount() {
        return communityMapper.selectRoomCount();
    }

    @Override
    public Integer inhabitedCount() {
        return communityMapper.selectInhabitedCount();
    }

    @Override
    public List<Community> communityRecommendList() {
        return communityMapper.selectCommunityListbyAssess();
    }

    @Override
    public List<Community> communityListByAddress(Address addressEntity) {
        return communityMapper.selectCommunityListByAddress(addressEntity);
    }

    @Override
    public List<Picture> getCommunityImg(Integer comId) {
        return communityMapper.selectCommunityImgs(comId);
    }

    @Override
    public Community getCommunityById(Integer comId) {
        return communityMapper.selectCommunityById(comId);
    }

    @Override
    public Address getCommunityAddress(Integer comId) {
        return communityMapper.getCommunityAddress(comId);
    }

    @Override
    public void checkIn(Integer addId, LocalDate checkInTime, LocalDate checkOutTime, Integer userId) {
        communityMapper.checkIn(addId, checkInTime, checkOutTime, userId);
    }

    @Override
    public void updateCommunity() {
        List<Integer> addIdList = communityMapper.selectCommunityIdList();
        if (addIdList.size() > 0) {
            for (Integer addId : addIdList) {
                communityMapper.updateCommunity(addId);
            }
        }
    }


}
